Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: backport complicated compiler changes #42180

Merged
merged 3 commits into from
Sep 9, 2021

Conversation

aviatesk
Copy link
Member

@aviatesk aviatesk commented Sep 9, 2021

This commit backports:

  1. 799136d (compiler: general refactor #41633)
  2. 795935f (more type-stable type-inference #41697)
  3. 3a4198e (inference: bail from const-prop if const-prop fails #42112)

where 3 depends on 2, which depends on 1.
1 and 2 are only refactors and we can try to avoid backporting them, but I decided to backport them as well
because we may want to backport more compiler changes in the future and it would be much easier to backport future changes with those commits.

aviatesk and others added 3 commits September 9, 2021 05:23
Separated from compiler-plugin prototyping.

cherry-picked from 799136d
(this PR is the final output of my demo at [our workshop](https://github.com/aviatesk/juliacon2021-workshop-pkgdev))

This PR eliminated much of runtime dispatches within our type inference
routine, that are reported by the following JET analysis:
```julia
using JETTest

const CC = Core.Compiler

function function_filter(@nospecialize(ft))
    ft === typeof(CC.isprimitivetype) && return false
    ft === typeof(CC.ismutabletype) && return false
    ft === typeof(CC.isbitstype) && return false
    ft === typeof(CC.widenconst) && return false
    ft === typeof(CC.widenconditional) && return false
    ft === typeof(CC.widenwrappedconditional) && return false
    ft === typeof(CC.maybe_extract_const_bool) && return false
    ft === typeof(CC.ignorelimited) && return false
    return true
end

function frame_filter((; linfo) = sv)
    meth = linfo.def
    isa(meth, Method) || return true
    return occursin("compiler/", string(meth.file))
end

report_dispatch(CC.typeinf, (CC.NativeInterpreter, CC.InferenceState); function_filter, frame_filter)
```

> on master
```
═════ 137 possible errors found ═════
...
```
> on this PR
```
═════ 51 possible errors found ═════
...
```

And it seems like this PR makes JIT slightly faster:
> on master
```julia
~/julia/julia master
❯ ./usr/bin/julia -e '@time using Plots; @time plot(rand(10,3));'
  3.659865 seconds (7.19 M allocations: 497.982 MiB, 3.94% gc time, 0.39% compilation time)
  2.696410 seconds (3.62 M allocations: 202.905 MiB, 7.49% gc time, 56.39% compilation time)
```
> on this PR
```julia
~/julia/julia avi/jetdemo* 7s
❯ ./usr/bin/julia -e '@time using Plots; @time plot(rand(10,3));'
  3.396974 seconds (7.16 M allocations: 491.442 MiB, 4.80% gc time, 0.28% compilation time)
  2.591130 seconds (3.48 M allocations: 196.026 MiB, 7.29% gc time, 56.72% compilation time)
```

cherry-picked from 795935f
Otherwise we can end up in an infinite cycle of attempting
const-prop, and that failing. Also handle `Varargs` in method-lookup
matching, which was the cause for which we could not compute the
const-prop signature.

Fixes #42097

cherry-picked from 3a4198e
@aviatesk aviatesk merged commit c6a090f into backports-release-1.7 Sep 9, 2021
@aviatesk aviatesk deleted the avi/backport-1.7 branch September 9, 2021 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants